
package com.android.matmanual;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

//import com.spreadtrum.android.eng.engfetch;
//import com.spreadtrum.android.eng.engconstents;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.TextView;

public class RFCalibrateInfo extends Activity {
	private static final String LOG_TAG = "adcCalibrateInfo";
	private int sockid = 0;
	//private engfetch mEf;
	private String str=null;
	private EventHandler mHandler;
	private TextView txtViewlabel01;
	WakeLock mWakeLock;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.textview_layout); 
        setTitle(R.string.rf_test);
        PowerManager pm =
		           (PowerManager) getSystemService(POWER_SERVICE); 
	    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, 
	          "XYTEST"); 
	    mWakeLock.acquire(); 
		txtViewlabel01= (TextView)findViewById(R.id.g_textView);
		txtViewlabel01.setTextSize(20);
		initial();
    }

    private void initial() {
		//mEf = new engfetch();
		//sockid = mEf.engopen();
		Looper looper;
		looper = Looper.myLooper();
		mHandler = new EventHandler(looper);
		mHandler.removeMessages(0);
		//Message msg = mHandler.obtainMessage(engconstents.ENG_AT_SGMR, 0, 0, 0);
		//mHandler.sendMessage(msg);
	}
    
    
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
    	int result = TestControl.GetKeyEvent(keyCode);
		if (result != TestControl.DO_NOTHING) {
			setResult(result);
			finish();
	    }
	    return true;
	}
	 
	 
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
        finish();
		super.onStop();
	}
		
    @Override
    protected void onDestroy() {
    	// TODO Auto-generated method stub
		if(mWakeLock!=null)
		{
			mWakeLock.release(); 
			mWakeLock = null;
		}
    	super.onDestroy();
    }	
	 
	@Override
	public void onAttachedToWindow() 
	{
		// TODO Auto-generated method stub
		super.onAttachedToWindow();
		this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
	} 
	private class EventHandler extends Handler
    {
    	public EventHandler(Looper looper) {
    	    super(looper);
    	}

    	@Override
    	public void handleMessage(Message msg) {
			/*switch(msg.what)
			{
			case engconstents.ENG_AT_SGMR:
				ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();
				DataOutputStream outputBufferStream = new DataOutputStream(outputBuffer);

				Log.e(LOG_TAG, "engopen sockid=" + sockid);

				str=String.format("%d,%d,%d,%d,%d", msg.what,3,0,0,3);
				try {
				    outputBufferStream.writeBytes(str);
				} catch (IOException e) {
				    Log.e(LOG_TAG, "writebytes error");
					return;
				}
				mEf.engwrite(sockid,outputBuffer.toByteArray(),outputBuffer.toByteArray().length);
				
				int dataSize = 512;
				byte[] inputBytes = new byte[dataSize];
				int showlen= mEf.engread(sockid,inputBytes,dataSize);
				String str =  new String(inputBytes, 0, showlen);
				txtViewlabel01.setText(str);
				break;
			}*/
    	}
    	
    	
    }    
	
}
		 